package studentinformationmanagementsystem.test;

import org.junit.Test;
import studentinformationmanagementsystem.entity.Page;
import studentinformationmanagementsystem.entity.Student;
import studentinformationmanagementsystem.entity.Teacher;
import studentinformationmanagementsystem.service.TeacherService;
import studentinformationmanagementsystem.service.impl.TeacherServiceImpl;
import studentinformationmanagementsystem.utils.TimeCycle;

import java.text.ParseException;
import java.util.List;

/**
 * @author 苗庆
 * @version 1.0
 */
public class TeacherTset {
    TeacherService teacherService = new TeacherServiceImpl();


    /**
     * 添加测试
     */
    @Test
    public void register() throws ParseException {
        for (int i = 0; i < 10; i++) {
            Teacher teacher = new Teacher(null, "李明", "513722199707014394", "男", "13600904451", "中共党员",
                    "汉族", "20210404_202411_014564_峡谷狂飙_Zxy男朋友.jpg", "2296877874@qq.com", TimeCycle.time("1996-09-07"),
                    "四川成都", "厦门集美", "24", "硕士研究生", TimeCycle.time("2003-09-07"),
                    "生活美好", "20030907", "1234");
            int register = teacherService.register(teacher);
            System.out.println(register);
        }
    }


    /**
     * 登陆测试
     */
    @Test
    public void login() {
        Teacher teacher = new Teacher();
        teacher.setTeachersworknumber("20030907");
        teacher.setPassword("1234");
        Teacher login = teacherService.login(teacher);
        System.out.println(login.toString());
    }


    /**
     * 检查教师工号是否已存在
     */
    @Test
    public void isExistsUsername() {
        Teacher teacher = new Teacher();
        teacher.setTeachersworknumber("20030907");
        boolean existsUsername = teacherService.isExistsUsername(teacher);
        System.out.println(existsUsername);
    }


    /**
     * 分页查询
     */
    @Test
    public void page() {

        Page<Teacher> page = teacherService.page(1, 5);
        System.out.println(page);
        List<Teacher> items = page.getItems();

        for (int i = 0; i < items.size(); i++) {
            Teacher teacher = items.get(i);
            System.out.println(teacher);
        }
    }



    /**
     *修改教师信息
     */
    @Test
    public void update() throws ParseException {
        Teacher teacher = new Teacher(2, "小明", "513722199707014394", "男", "13600904451", "中共党员",
                "汉族", "20210404_202411_014564_峡谷狂飙_Zxy男朋友.jpg", "2296877874@qq.com", TimeCycle.time("1996-09-07"),
                "四川成都", "厦门集美", "24", "硕士研究生", TimeCycle.time("2003-09-07"),
                "生活美好", "20030907", "1234");
        int update = teacherService.update(teacher);
        System.out.println(update);
    }


    /**
     * 删除教师信息
     *
     */
    @Test
    public void delete(){

        Teacher teacher = new Teacher();
        teacher.setTeacherid(2);
        int delete = teacherService.delete(teacher);
        System.out.println(delete);
    }

    /**
     * 查询所以教师信息
     */
    @Test
    public void queryAll(){
        List<Teacher> teachers = teacherService.queryAll();
        for (int i = 0; i <teachers.size() ; i++) {
            Teacher teacher = teachers.get(i);
            System.out.println(teacher);
        }
    }

    /**
     * 根据id查询所有学生信息
     */

    @Test
    public void queryById(){
        Teacher teacher = new Teacher();
        teacher.setTeacherid(10);
        Teacher teacher1 = teacherService.queryById(teacher);
        System.out.println(teacher1);
    }

}
